<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>OOJS</title>
    <script src="./js/js02_oojs_02.js" async></script>
    <link rel="stylesheet" href="./style/common.css">
</head>
<body>
    <h1>OOJS-封装</h1>
    <p class="msg"></p>
    <script>
        document.addEventListener("DOMContentLoaded",function(){
            let msg=document.querySelector(".msg");
            let stu1=new Student("张三",20);
            msg.innerHTML+=stu1.sayHello();
            msg.innerHTML+="<br>";
            stu1.name="李四";
            stu1.age=21;
            msg.innerHTML+=stu1.sayHello();
            msg.innerHTML+="<br>";
            stu1.setAge(22);
            msg.innerHTML+=stu1.sayHello();
            msg.innerHTML+="<br>";

            let stu2=new Student2("王五");
            msg.innerHTML+=stu2.sayHello();
            console.log(stu2[symbolAge]);
            console.log(Object.keys(stu2));

            stu2.setAge(23);
            msg.innerHTML+=stu2.sayHello();
            msg.innerHTML+="<br>";

            let stu3=new Student2("赵柳");
            try{
                stu3.setAge(-1);
            }catch(e){
                msg.innerHTML+=`<span class="danger">${e}<span>`;
            }
        });
        Student.prototype.test=function(){
            console.log("原型链会自动更新");
        }
        stu1.test();
    </script>
</body>
</html>